package com.vietnam.power.persitence;

import java.io.Serializable;

import javax.persistence.*;

import com.vietnam.power.domain.Root;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the product database table.
 * 
 */
@Entity
@Table(name="product")
public class Product implements Serializable, Root {
	private static final long serialVersionUID = 1L;
	private int id;
	private boolean available;
	private Date createdDate;
	private String description;
	private String highlight;
	private String keyword;
	private String name;
	private int quantity;
	private String shortDescription;
	private boolean status;
	private BigDecimal unitPrice;
	private List<TxnProduct> txnProducts;
	private List<Comment> comments;
	private UserInfo userInfo;
	private ProductGroup productGroup;
	private List<ProductImage> productImages;

	public Product() {
	}

	public Product(int id) {
		this.id = id;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public boolean getAvailable() {
		return this.available;
	}

	public void setAvailable(boolean available) {
		this.available = available;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "created_date")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Lob
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getHighlight() {
		return this.highlight;
	}

	public void setHighlight(String highlight) {
		this.highlight = highlight;
	}

	public String getKeyword() {
		return this.keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getQuantity() {
		return this.quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	@Column(name = "short_description")
	public String getShortDescription() {
		return this.shortDescription;
	}

	public void setShortDescription(String shortDescription) {
		this.shortDescription = shortDescription;
	}

	public boolean getStatus() {
		return this.status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	@Column(name = "unit_price")
	public BigDecimal getUnitPrice() {
		return this.unitPrice;
	}

	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}

	// bi-directional many-to-one association to TxnProduct
	@OneToMany(mappedBy = "product")
	public List<TxnProduct> getTxnProducts() {
		return this.txnProducts;
	}

	public void setTxnProducts(List<TxnProduct> txnProducts) {
		this.txnProducts = txnProducts;
	}

	public TxnProduct addTxnProduct(TxnProduct txnProduct) {
		getTxnProducts().add(txnProduct);
		txnProduct.setProduct(this);

		return txnProduct;
	}

	public TxnProduct removeTxnProduct(TxnProduct txnProduct) {
		getTxnProducts().remove(txnProduct);
		txnProduct.setProduct(null);

		return txnProduct;
	}

	// bi-directional many-to-one association to Comment
	@OneToMany(mappedBy = "product")
	public List<Comment> getComments() {
		return this.comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	public Comment addComment(Comment comment) {
		getComments().add(comment);
		comment.setProduct(this);

		return comment;
	}

	public Comment removeComment(Comment comment) {
		getComments().remove(comment);
		comment.setProduct(null);

		return comment;
	}

	// bi-directional many-to-one association to UserInfo
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "created_by")
	public UserInfo getUserInfo() {
		return this.userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	// bi-directional many-to-one association to ProductGroup
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "product_group_id")
	public ProductGroup getProductGroup() {
		return this.productGroup;
	}

	public void setProductGroup(ProductGroup productGroup) {
		this.productGroup = productGroup;
	}

	// bi-directional many-to-one association to ProductImage
	@OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval=true)
	public List<ProductImage> getProductImages() {
		if (this.productImages == null) {
			this.productImages = new ArrayList<ProductImage>();
		}
		return this.productImages;
	}

	public void setProductImages(List<ProductImage> productImages) {
		this.productImages = productImages;
	}

	public ProductImage addProductImage(ProductImage productImage) {
		getProductImages().add(productImage);
		productImage.setProduct(this);

		return productImage;
	}

	public ProductImage removeProductImage(ProductImage productImage) {
		getProductImages().remove(productImage);
		productImage.setProduct(null);

		return productImage;
	}

}